package Terminal.UI.InterfacceConsulente;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.text.DateFormat;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;

import com.toedter.calendar.JCalendar;

import Terminal.Entity.ETaskI;
import Terminal.Entity.ETimeRecordI;
import Terminal.UI.PanelComponent;
import Terminal.UI.PannelloDatiDecoretor;
import Terminal.UI.TimeLoggingFrame;

public class PannelloDatiTimerecord extends PannelloDatiDecoretor{
private ETimeRecordI timerecord;

	private JLabel timerecordidlabel;
	private JLabel timerecordidtextlabel;
	private JLabel timerecordiniziolabel;
	private JLabel timerecordiniziotextlabel;
	private JLabel timerecordfinelabel;
	private JLabel timerecordfinetextlabel;

	private JLabel timerecorddescrizionelabel;
	private JTextPane timerecorddescrizionetext;

	public PannelloDatiTimerecord (PanelComponent parent, ETimeRecordI time){
		super(parent);
		this.timerecord=time;
	}
	@Override
	public JPanel createComponents() {
		
		pannellocomponente = new JPanel(null);
		pannellocomponente.setBackground(Color.white);
		
        /*title= BorderFactory.createTitledBorder("Descrizione progetto");
        pannellocomponente.setBorder(title);*/
		////////////////////////////////////PANNELLO DI DESCRIZIONE////////////////////////////////////
	
		
		
		timerecordidlabel = new JLabel("Identificatore:");
		timerecordidlabel.setLocation(50,10);
		timerecordidlabel.setPreferredSize(new Dimension(200,40));
		timerecordidlabel.setSize(timerecordidlabel.getPreferredSize());
		timerecordidlabel.setFont(new Font(timerecordidlabel.getFont().getName(), Font.BOLD, size_font_title));
		pannellocomponente.add(timerecordidlabel);
       
        
		timerecordidtextlabel= new JLabel();
		
		timerecordidtextlabel.setLocation(220,10);//timerecordidlabel.getLocation().y);
		timerecordidtextlabel.setPreferredSize(new Dimension(200,40));
		timerecordidtextlabel.setSize(timerecordidtextlabel.getPreferredSize());
		pannellocomponente.add(timerecordidtextlabel);
		
		timerecordidtextlabel.setFont(new Font(timerecordidtextlabel.getFont().getFontName(), Font.ITALIC,size_font_values));

		timerecorddescrizionelabel = new JLabel("Commento:");
		//timerecorddescrizionelabel.setLocation(50, timerecordidlabel.getLocation().y+timerecordidlabel.getPreferredSize().height+5);
		timerecorddescrizionelabel.setLocation(50,50);
		timerecorddescrizionelabel.setPreferredSize(new Dimension(200,40));
		timerecorddescrizionelabel.setSize(timerecorddescrizionelabel.getPreferredSize());
		timerecorddescrizionelabel.setFont(new Font(timerecorddescrizionelabel.getFont().getName(), Font.BOLD, size_font_title));
		pannellocomponente.add(timerecorddescrizionelabel);
        
        timerecorddescrizionetext = new JTextPane();
        
        JScrollPane scrollpanetesto = new JScrollPane(timerecorddescrizionetext);
       
        scrollpanetesto.setLocation(220,timerecorddescrizionelabel.getLocation().y);
        scrollpanetesto.setPreferredSize(new Dimension(200,40));
        scrollpanetesto.setSize(scrollpanetesto.getPreferredSize());
       	timerecorddescrizionetext.setEditable(false);
		pannellocomponente.add(scrollpanetesto);
		
		
		timerecordiniziolabel = new JLabel("Data di inizio:");
		//timerecordiniziolabel.setLocation(50, scrollpanetesto.getLocation().y+scrollpanetesto.getPreferredSize().height+5);
		timerecordiniziolabel.setLocation(50, 90);
		timerecordiniziolabel.setPreferredSize(new Dimension(200,40));
		timerecordiniziolabel.setSize(timerecordiniziolabel.getPreferredSize());
		timerecordiniziolabel.setFont(new Font(timerecordiniziolabel.getFont().getName(), Font.BOLD, size_font_title));
		pannellocomponente.add(timerecordiniziolabel);
        
		timerecordiniziotextlabel = new JLabel();
		timerecordiniziotextlabel.setLocation(220,timerecordiniziolabel.getLocation().y);
		timerecordiniziotextlabel.setPreferredSize(new Dimension(200,40));
		timerecordiniziotextlabel.setSize(timerecordiniziotextlabel.getPreferredSize());
		pannellocomponente.add(timerecordiniziotextlabel);
		timerecordiniziotextlabel.setFont(new Font(timerecordiniziotextlabel.getFont().getFontName(), Font.ITALIC,size_font_values));
		
			
			

	
		timerecordfinelabel = new JLabel("Data di Fine:");
		timerecordfinelabel.setLocation(50,timerecordiniziolabel.getLocation().y+timerecordiniziolabel.getPreferredSize().height+5);
		timerecordfinelabel.setPreferredSize(new Dimension(200,40));
		timerecordfinelabel.setSize(timerecordfinelabel.getPreferredSize());
		timerecordfinelabel.setFont(new Font(timerecordfinelabel.getFont().getName(), Font.BOLD, size_font_title));
		pannellocomponente.add(timerecordfinelabel);
		//System.out.print("\n datafine"+timerecordfinelabel.getLocation());
        
        timerecordfinetextlabel = new JLabel();
        timerecordfinetextlabel.setLocation(220,timerecordfinelabel.getLocation().y);
		timerecordfinetextlabel.setPreferredSize(new Dimension(200,40));
		timerecordfinetextlabel.setSize(timerecordfinetextlabel.getPreferredSize());
		pannellocomponente.add(timerecordfinetextlabel);
			
		timerecordfinetextlabel.setFont(new Font(timerecordfinetextlabel.getFont().getFontName(), Font.ITALIC,size_font_values));
		//if(progetto.getScadenza()!=null)progettoscadenzatextlabel.setText(progetto.getScadenza().getDay()+"-"+progetto.getScadenza().getMonth()+"-"+(((int) progetto.getScadenza().getYear())+1900));
		
		
		

		
		visualizzaElemento(timerecord);
		
		setSize(timerecordfinetextlabel.getLocation().x+timerecordfinetextlabel.getSize().width+75,timerecordfinetextlabel.getLocation().y+timerecordfinetextlabel.getSize().height+25);
		
		//setSize(700,600);

		return pannellocomponente;
	}
	
	public void visualizzaElemento(Object obj) {
		
		this.timerecord =(ETimeRecordI) obj;
		SimpleDateFormat dataformat= new SimpleDateFormat("dd/MM/yyyy HH:mm");
		SimpleDateFormat dataformat2 = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy",Locale.ENGLISH);
		try{timerecordidtextlabel.setText(timerecord.getId()+" ");} catch (Exception e) {timerecordidtextlabel.setText("  ");		}
		try{
			if(timerecord.getDataInizio()!=null) 	
			{
				Date datetemp = timerecord.getDataInizio();
				timerecordiniziotextlabel.setText(dataformat.format(datetemp));
				}
		else timerecordiniziotextlabel.setText("  "); 
			}
		catch (Exception e) {	timerecordiniziotextlabel.setText(" ");		}
		try{
			if(timerecord.getDataFine()!=null)
			{
				Date datetemp = timerecord.getDataFine();
				timerecordfinetextlabel.setText(dataformat.format(datetemp));
				}
			else timerecordfinetextlabel.setText(" ");}
		catch (Exception e) {	timerecordfinetextlabel.setText(" ");	}
		try{if(timerecord.getTesto()!=null) timerecorddescrizionetext.setText(timerecord.getTesto());else timerecorddescrizionetext.setText(" ");} catch (Exception e) { timerecorddescrizionetext.setText(" ");}
	}
	@Override
	public void updateSize() {}

	
}
